package backboneCode;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JOptionPane;

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

public class ConsoleCode {

	public int reciveCall(int number, String msg)
	{
		String s="";
		MessageConsole newConsoleTabb = findConsole("Console Test Name");
		
		MessageConsoleStream out = newConsoleTabb.newMessageStream();
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH.mm");
		Date date = new Date();
		
		
		switch(number)
		{
		case 1:					//First launch of console a launch msg and some general information should be provided.
			out.println("ArCon specific console have been started, current date is: " + dateFormat.format(date));
			
		break;
		
		case 2:					//Main content output view, should be used in cases where large amounts of data is to be presented (will require abit of tweeking)
			s = msg;
			
			out.println("This is a output test inputdata: " + s);			
		break;

		case 3:					// Specific case for printing ERROR messages
		break;
		
		case 4:					// If user input is required.....cind of just good to have
			s= (String)JOptionPane.showInputDialog(null);

			out.println("This is a output test inputdata: " + s);			
			
		break;
		
		default:
		break;
		}
		
		return 0;
	}

	
	private MessageConsole findConsole(String name) {
		//Activate Plugin
		ConsolePlugin usedPlugin = ConsolePlugin.getDefault();
		//Create "private Console Manager"
		IConsoleManager conPrivateManager = usedPlugin.getConsoleManager();
		//Control if any console "manager" with the requested name exists
		IConsole[] existing = conPrivateManager.getConsoles();
		for (int i = 0; i < existing.length; i++)
		{
			if (name.equals(existing[i].getName()))
			{
				return (MessageConsole) existing[i];
			}
		}
		//If no "manager found" one is created
		MessageConsole myConsole = new MessageConsole(name, null);

		conPrivateManager.addConsoles(new IConsole[]{myConsole});
		conPrivateManager.showConsoleView(myConsole);
		//return console for usage (Ie Message output)
		return myConsole;
		}
}
